package common.config.datasource.sharding.config;

import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

/**
 * ShardingSphere算法配置
 *
 * @author 米泽鹏
 * @since 2023-7-29 下午 7:07
 */
public class ShardingSphereAlgorithmConstants {

	/**
	 * 读写分离的负载均衡算法
	 */
	public static final Map<String, ShardingSphereAlgorithmConfiguration> READWRITE_ALGORITHMS = new HashMap<>();

	/**
	 * 算法名称：读写分离算法（ROUND_ROBIN）
	 */
	public static final String READWRITE_ALG_ROUND = "alg_round";

	/**
	 * 算法名称：读写分离算法（RANDOM）
	 */
	public static final String READWRITE_ALG_RANDOM = "alg_random";

	/**
	 * 算法名称：读写分离算法（WEIGHT）
	 */
	public static final String READWRITE_ALG_WEIGHT = "alg_weight";

	/**
	 * 数据分片算法
	 */
	public static final Map<String, ShardingSphereAlgorithmConfiguration> SHARDING_ALGORITHMS = new LinkedHashMap<>();

	static {
		// 负载均衡算法
		READWRITE_ALGORITHMS.put(READWRITE_ALG_ROUND, new ShardingSphereAlgorithmConfiguration("ROUND_ROBIN", null));
		READWRITE_ALGORITHMS.put(READWRITE_ALG_RANDOM, new ShardingSphereAlgorithmConfiguration("RANDOM", null));
		Properties properties = new Properties();
		properties.setProperty("slave01", "1");
		properties.setProperty("slave02", "2");
		READWRITE_ALGORITHMS.put(READWRITE_ALG_WEIGHT, new ShardingSphereAlgorithmConfiguration("WEIGHT", properties));
	}

}
